/* GUI CONVERTED from rsgetord.i (converter v1.76) Thu Feb 28 19:34:11 2002 */
/* rsgetord.i - Release Management Supplier Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.14.1.4 $                                                      */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3    LAST MODIFIED: 09/30/92           BY: WUG *G462*          */
/* REVISION: 7.3    LAST MODIFIED: 05/06/93           BY: WUG *GA72*          */
/* REVISION: 7.3    LAST MODIFIED: 05/24/93           BY: WUG *GB29*          */
/* REVISION: 7.3    LAST MODIFIED: 07/13/93           BY: WUG *GD42*          */
/* REVISION: 7.3    LAST MODIFIED: 04/25/94           BY: WUG *GJ59*          */
/* REVISION: 7.5    LAST MODIFIED: 12/13/94           BY: mwd *J034*          */
/* REVISION: 7.3    LAST MODIFIED: 03/10/95           BY: jxz *G0H2*          */
/* REVISION: 7.3    LAST MODIFIED: 07/03/95           BY: dxk *G0RK*          */
/* REVISION: 8.5    LAST MODIFIED: 04/18/96           BY: rpw *J0JN*          */
/* REVISION: 8.5    LAST MODIFIED: 04/30/96           BY: rpw *J0KM*          */
/* REVISION: 8.5    LAST MODIFIED: 05/07/96           BY: taf *J0LG*          */
/* REVISION: 8.5    LAST MODIFIED: 06/04/96           BY: *J0QS* M. Deleeuw   */
/* REVISION: 8.6    LAST MODIFIED: 05/09/97           BY: *K0D1* Jean Miller  */
/* REVISION: 8.5    LAST MODIFIED: 06/05/97           BY: *J1R8* Jean Miller  */
/* REVISION: 8.5    LAST MODIFIED: 03/09/98           BY: *J2G8* Jean Miller  */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98           BY: *K1Q4* Alfred Tan   */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00     BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00     BY: *N0KP* Mark Brown         */
/* REVISION: 9.1    LAST MODIFIED: 08/29/00     BY: *N0PM* Arul Victoria      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.14.1.4 $   BY: Jean Miller       DATE: 02/27/02  ECO: *N1BB*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* GETS A SCHEDULED ORDER XREF RECORD (scx_ref) */

/*
{1}="old" if the record has to exist
{2}= command to execute within next/previous
{3}="anything" to prevent assurance that the user is in the proper db
{4}="anything" to include site security check.  (update progms need site
               security where inquiry/report pgms do not)
*/

define new shared variable global_order as character.
define new shared variable global_line as integer.
define new shared variable global_recid as recid.

define variable tmp-scx-po like scx_ref.scx_po no-undo.

define shared variable window_recid as recid.

recno = recid(scx_ref).

loopa:
do with frame a:

   on leave of scx_po in frame a do:

      tmp-scx-po = input frame a scx_po.

           
      do on error undo, leave:
         run q-leave in global-drop-down-utilities.
      end.
      run q-set-window-recid in global-drop-down-utilities.
      if return-value = "error" then return no-apply.   

   end.

   on leave of scx_part in frame a do:

           
      do on error undo, leave:
         run q-leave in global-drop-down-utilities.
      end.
      run q-set-window-recid in global-drop-down-utilities.   

      if window_recid <> ? then do:

         find first pod_det where recid(pod_det) = window_recid
         no-lock no-error.

         if available pod_det then do:

            find first scx_ref no-lock where (scx_type = 2 and
            scx_order = pod_nbr and scx_line = pod_line) no-error.

            if available scx_ref then do:

               find ad_mstr where ad_addr = scx_shipfrom
               no-lock no-error.

               display
                  scx_shipfrom
                  scx_shipto
                  ad_name when (available ad_mstr)
                  scx_part
                  pod_um
                  pod_vpart
                  scx_po
                  scx_line
               with frame a.

            end.

         end.

         window_recid = ?.

      end. /* if window_recid <> ? */

      if return-value = "ERROR" then return no-apply.

   end. /* on leave of scx_part */

   run get-input.

   if keyfunction(lastkey) = "end-error" then undo, leave.

   find scx_ref where scx_type = 2
                  and scx_shipfrom = input frame a scx_shipfrom
                  and scx_shipto = input frame a scx_shipto
                  and scx_part = input frame a scx_part
                  and scx_po = input frame a scx_po
   no-lock no-error.

   if not available scx_ref then
   find scx_ref where scx_type = 2
                  and scx_order = input frame a scx_po
                  and scx_line = input frame a scx_line
   no-lock no-error.

   if "{1}" = "old" and not available scx_ref then do:
      /* SCHEDULED ORDER DETAIL RECORD DOES NOT EXIST */
      {pxmsg.i &MSGNUM=8172 &ERRORLEVEL=3}
      bell.
      undo, retry.
   end.

   if available scx_ref then do:

      /* NOTE SHIPTO ACTUALLY BEING USED IS THE ONE ON FILE.  IF THE */
      /* USER ATTEMPTS TO INQUIRE ON A VALID PO/LINE BUT ENTERS THE  */
      /* WRONG SHIP-TO WITH IT OR DOESN'T KNOW THE SHIP-TO, THE      */
      /* PROGRAM WILL JUST USE THE PO/LINE TO FIND THE ORDER.  SO    */
      /* DON'T USE THE ENTERED SHIP-TO, IT MAY NOT BE VALID.         */

      find si_mstr where si_site =  scx_shipto no-lock.

            find ad_mstr where ad_addr = scx_shipfrom no-lock.
            find pt_mstr where pt_part = scx_part no-lock.
            find pod_det where pod_nbr = scx_po and
            pod_line = scx_line no-lock.

      run check-sched.

      display
         scx_shipfrom
         scx_shipto
         ad_name
         scx_part
         pod_um
         pod_vpart
         scx_po
         scx_line.

      if "{3}" = "" and si_db <> global_db then do:
         /* You must be in database # */
         {pxmsg.i &MSGNUM=8148 &ERRORLEVEL=3 &MSGARG1=si_db}
         undo, retry.
      end.

      assign
         global_order = pod_nbr
         global_line = pod_line.

      {gpbrparm.i &browse=gplu539.p &parm=c-brparm1 &val="global_order"}
      {gpbrparm.i &browse=gplu539.p &parm=c-brparm2 &val="string(global_line)"}

      /*   IF UPDATE APPLICATION, CHECK SITE SECURITY **/
      if "{4}" <> "" then do:
         {gprun.i ""gpsiver.p""
             "(input si_site, input recid(si_mstr), output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            display scx_shipto with frame a.
            /* USER DOES NOT HAVE ACCESS TO SITE */
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            undo, retry.
         end.
      end.

   end. /* IF AVAILABLE SCX_REF */

end. /* LOOPA */

PROCEDURE check-sched:
/* -----------------------------------------------------------
  Purpose:     Check to see if Valid scheduled order
  Parameters:  <none>
  Notes:
-------------------------------------------------------------*/

   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      if pod_det.pod_start_eff[1] > today or pod_end_eff[1] < today
      then do:
         /* Scheduled Order is no longer effective */
         {pxmsg.i &MSGNUM=8173 &ERRORLEVEL=2}
         return.
      end.

      if pod_cum_qty[1] >= pod_cum_qty[3] and pod_cum_qty[3] > 0
      then do:
         /* "Cum Rcvd Qty >= Max Order Qty */
         {pxmsg.i &MSGNUM=8232 &ERRORLEVEL=2}
         return.
      end.

      if not pod_sched then do:
         /* Line item in not scheduled */
         {pxmsg.i &MSGNUM=6004 &ERRORLEVEL=3}
         return error.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


END PROCEDURE. /* check-sched */

PROCEDURE get-input:
/* -----------------------------------------------------------
 Purpose: Prompt for order parameters, next-previous key processing
 Parameters: <none>
 Notes:
-------------------------------------------------------------*/

   do on error undo, retry on endkey undo, leave with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


      prompt-for scx_po scx_part scx_shipfrom scx_shipto scx_line
      editing:

         assign
            global_order = input frame a scx_po
            global_line = input frame a scx_line.

         {gpbrparm.i &browse=gplu539.p &parm=c-brparm1 &val="global_order"}
         {gpbrparm.i &browse=gplu539.p &parm=c-brparm2
                     &val="string(global_line)"}

         if frame-field = "scx_shipfrom" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 2"
            scx_shipfrom "input frame a scx_shipfrom"}
         end. /* IF FRAME-FIELD = SCX_SHIPFROM */

         else
         if frame-field = "scx_shipto" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 2
            and scx_shipfrom = input frame a scx_shipfrom"
            scx_shipto "input frame a scx_shipto"}
         end. /* IF FRAME-FIELD = SCX_SHIPTO */

         else
         if frame-field = "scx_part" then do:
            /* BY SETTING global_recid TO ?, ONLY ROUTINES THAT SET
               THIS VALUE WILL HAVE AN EFFECT HERE.  CURRENTLY, ONLY
               THE ROUTINE swrspoln.p SETS THIS GLOBAL.  OF COURSE,
               WHEN IT *IS* SET, IT MUST BE SET TO POINT TO A SCHEDULED
               pod_det RECORD. */

            global_recid = ?.

            if tmp-scx-po = "" then do:

               {mfnp05.i pod_det pod_part
                 "pod_sched"
                 pod_part "input frame a scx_part"}

               if recno <> ? then do:

                  find po_mstr where po_nbr = pod_nbr no-lock.
                  find scx_ref where scx_po = pod_nbr
                              and scx_line = pod_line
                              and scx_type = 2 and scx_part = pod_part
                              and scx_shipto = pod_site
                              and scx_shipfrom = po_vend
                  no-lock no-error.
                  if not available scx_ref then do:
                     recno = ?.
                     display
                        "" @ scx_po
                        pod_part @ scx_part
                        "" @ scx_shipfrom
                        "" @ scx_shipto
                        "" @ ad_name.
                  end.

               end.

            end.  /* if tmp-scx-po = "" */

            else do:
               {mfnp05.i scx_ref scx_po
                 "scx_type = 2 and scx_po = input frame a scx_po"
                 scx_part "input frame a scx_part"}
            end.

         end. /* IF FRAME-FIELD = SCX_PART */

         else
         if frame-field = "scx_po" then do:
            {mfnp05.i scx_ref scx_po "scx_type = 2"
              scx_po "input frame a scx_po"}
         end. /* IF FRAME-FIELD = SCX_PO */

         else
         if frame-field = "scx_line" then do:
            {mfnp05.i scx_ref scx_order
              "scx_type = 2 and scx_order = input frame a scx_po"
              scx_line "input frame a scx_line"}
         end. /* IF FRAME-FIELD = SCX_LINE */

         else do:
            status input.
            readkey.
            apply lastkey.
         end.

         if recno <> ? then do:

            find si_mstr where si_site = scx_shipto no-lock.
            find ad_mstr where ad_addr = scx_shipfrom no-lock.
            find pt_mstr where pt_part = scx_part no-lock.
            find pod_det where pod_nbr = scx_po and
                               pod_line = scx_line no-lock.

            display
               scx_shipfrom
               scx_shipto
               ad_name
               scx_part
               pod_um
               pod_vpart
               scx_po
               scx_line.
            {2}

         end.

      end. /* PROMPT-FOR...EDITING */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* do on error undo, retry .. */

END PROCEDURE. /* get-input */
